package eerbaar.v2.app.mouse;

import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.util.ArrayList;
import java.util.List;

public class MouseListenerList implements MouseMotionListener, MouseListener {

    private final List<IMouseListener> list = new ArrayList<IMouseListener>();

    public void addMouseListener(IMouseListener mouseListener) {
        this.list.add(0, mouseListener);
    }

    public void fireMouseClicked(MouseEvent e) {
        MouseEvent2 event = new MouseEvent2(e.getX(), e.getY());
        for (IMouseListener l : this.list) {
            l.mouseClicked(event);
            if (event.isStopped()) {
                break;
            }
        }
    }

    public void fireMouseExited(MouseEvent e) {
        for (IMouseListener l : this.list) {
            l.mouseExited();
        }
    }

    public void fireMouseMoved(MouseEvent e) {
        MouseEvent2 event = new MouseEvent2(e.getX(), e.getY());
        for (IMouseListener l : this.list) {
            l.mouseMoved(event);
            if (event.isStopped()) {
                break;
            }
        }
    }

    @Override
    public void mouseClicked(MouseEvent e) {
        fireMouseClicked(e);
    }

    @Override
    public void mouseDragged(MouseEvent e) {
        //
    }

    @Override
    public void mouseEntered(MouseEvent e) {
        //
    }

    @Override
    public void mouseExited(MouseEvent e) {
        fireMouseExited(e);
    }

    @Override
    public void mouseMoved(MouseEvent e) {
        fireMouseMoved(e);
    }

    @Override
    public void mousePressed(MouseEvent e) {
        //
    }

    @Override
    public void mouseReleased(MouseEvent e) {
        //
    }

}
